package net.com.sunkey.messagehandler;

import net.com.sunkey.protobuf.Protocol;
import net.com.sunkey.protobuf.PrivateMsgByNameRequest.PrivateMsgByNameRequestData;
import net.com.sunkey.serverlogic.Message;
import net.com.sunkey.serverlogic.User;

/**
 * @author kohachiro
 *
 */
public class PrivateMsgByNameRequestHandler {

	/**
	 * 
	 */
	//@Override
	public static int invoke(Object data, Object channel) throws Exception {
		System.out.println("["+channel.hashCode()+"]["+Protocol.MessageHandler.PrivateMsgByNameRequest_VALUE+"]PrivateMsgByNameRequest");
		User toUser=User.get(((PrivateMsgByNameRequestData)data).getUsername());
		if (toUser!=null){
			User sender=User.get(channel);			
			Message mesage=new Message(((PrivateMsgByNameRequestData)data).getMessage(),sender,Protocol.MessageRouter.ROUTER_USER_VALUE);		
			NewMessageResponseHandler.invoke(mesage, toUser.getChannel());
		}
		return Protocol.MessageHandler.PrivateMsgByNameRequest_VALUE;
	}
}
